#ifndef DEBUG_H
#define DEBUG_H
    
#if defined (__GNUC__)  // GNU C defined
    
    #if defined(DEBUG)  
        
        #define DEBUG_PRINT(fmt, args...) printf("DEBUG: " fmt, ##args)

        #define DEBUG_ASSERT_WARNING(val) do{ \
                                            if(!(val)) {\
                                                DEBUG_PRINT ("ASSERTION FAIL at File %s, Line %d\n", __FILE__, __LINE__); \
                                            } \
                                        }while(0)
        
        #define DEBUG_ASSERT_FATAL(val) do { \
                                            DEBUG_ASSERT_WARNING(val); \
                                            if(!(val)) { \
                                                *((int*)0) = 0; \
                                            } \
                                        } while (0)

    #else
        #define DEBUG_PRINT(fmt, args...)
        #define DEBUG_ASSERT_WARNING (val)
        #define DEBUG_ASSERT_FATAL(val)
    #endif

#else   //  GNU C not defined

    #if defined(DEBUG)  
        
        #define DEBUG_PRINT(fmt, args) printf("DEBUG: " fmt, ##args)

        #define DEBUG_ASSERT_WARNING(val) do{ \
                                            if(!(val)) {\
                                                DEBUG_PRINT ("ASSERTION FAIL at File %s, Line %d\n", __FILE__, __LINE__); \
                                            } \
                                        }while(0)
        
        #define DEBUG_ASSERT_FATAL(val) do { \
                                            DEBUG_ASSERT_WARNING(val); \
                                            if(!(val)) { \
                                                *((int*)0) = 0; \
                                            } \
                                        } while (0)

    #else
        #define DEBUG_PRINT(fmt, args)
        #define DEBUG_ASSERT_WARNING (val)
        #define DEBUG_ASSERT_FATAL(val)
    #endif

        
#endif


#define C_ASSERT(cond) \
    extern char compile_time_assertion[(cond) ? 1 : -1]

#endif
